package com.kch.system.service.impl;

import com.kch.system.domain.AuditRecord;
import com.kch.system.domain.SysBusiness;
import com.kch.system.domain.SysUser;
import com.kch.system.mapper.AuditRecordMapper;
import com.kch.system.mapper.SysBusinessMapper;
import com.kch.system.service.ISysBusinessService;
import com.kch.system.vo.SysBusinessVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

@Service
public class SysBusinessServiceImpl implements ISysBusinessService {

    @Autowired
    private SysBusinessMapper sysBusinessMapper;
    @Autowired
    private AuditRecordMapper auditRecordMapper;

    @Override
    public List<SysBusinessVO> selectListPage(SysBusiness record) {
        return sysBusinessMapper.selectListPage(record);
    }

    @Override
    public int updateStatus(Integer id) {
        SysBusiness sysBusiness = sysBusinessMapper.selectByPrimaryKey(id);
        String status = ("0".equals(sysBusiness.getStatus())? "1" : "0");
        return sysBusinessMapper.updateStatus(id, status);
    }

    @Override
    public int insertSysBusiness(SysBusiness sysBusiness) {
        sysBusiness.setCreateTime(new Date());
        return sysBusinessMapper.insert(sysBusiness);
    }

    @Override
    public SysBusinessVO selectById(Integer id) {
        SysBusinessVO sysBusinessVO = sysBusinessMapper.selectById(id);
        sysBusinessVO.setXqPriceType(sysBusinessVO.getPriceType());
        sysBusinessVO.setWtPriceType(sysBusinessVO.getPriceType());
        return  sysBusinessVO;
    }

    @Override
    public SysBusiness selectSysById(Integer id) {
        return sysBusinessMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<SysBusiness> selectOutListPage(SysBusiness business) {
        return sysBusinessMapper.selectOutListPage(business);
    }

    @Override
    public int deleteBusiness(String ids) {
        return sysBusinessMapper.deleteByPrimaryKey(Integer.valueOf(ids));
    }

    @Override
    public int updateById(SysBusiness sysBusiness) {
        return sysBusinessMapper.updateByPrimaryKeyWithBLOBs(sysBusiness);
    }

    @Override
    public List<SysBusiness> selectPageByUserId(SysUser sysUser) {
        return sysBusinessMapper.selectPageByUserId(sysUser.getUserId().intValue());
    }
}
